    var $;
    var layer;
    var table;
    var form;
    layui.use(['layer', 'table', 'form'], function () {
        layer = layui.layer;
        $ = layui.jquery;
        table = layui.table;
        form = layui.form;
        getTab();
        getcomment();//评论区初始化
        //获取当前登陆人员的信息
        var create=localStorage.getItem("user");
        create=JSON.parse(create);//将获取json字符串转json对象
        $("#sendUserName").val(create.true_name);
        $("#sendUserAccount").val(create.account);
        var id=$("#courseId").val();
        selEassyImgs(id);
 });
    //获取商品的图片
    function selEassyImgs(id){
        var pictureType = 4;
        $.post('/SyOperationController/selCommodityImgs',{"microcircleId":id,"pictureType":pictureType},function(res){
            for(var i=0;i<res.data.length;i++){
                $(".td4").append("<img src="+res.data[i].articleUrl+" id=\"img\">")
            }
        })
    }
 //初始化表格
 function getTab() {
     var id=$("#courseId").val();
     $.ajax({
         url:"/SyOperationController/selCommodityInfo",
         type:"post",
         dataType:"json",
         data:{"microcircleId":id},
         success:function(data){
             if(data.code>-1){
                 var obj = data.data;

                 $("#img").attr("src",obj.mainImage);//封面图url
                 $('input[name=productName]').val(obj.productName);

                 var createDate=obj.createDate;
                 createDate = createDate.slice(0, createDate.indexOf("."));
                 createDate = createDate.replaceAll('T',' ');
                 $('input[name=createDate]').val(createDate);

                 $('input[name=userNames]').val(obj.userNames);
                 $('input[name=createUser]').val(obj.createUser);
                 $('input[name=currentpriceProduct]').val("￥ "+obj.currentpriceProduct);
                 $('input[name=searchKeywords]').val(obj.searchKeywords);
                 $('input[name=categoryName]').val(obj.categoryName);
                 $('input[name=productCode]').val(obj.productCode);
                 $('input[name=discount]').val(obj.discount);
                 $('input[name=productLabel]').val(obj.productLabel);
                 if(obj.productSate==2){
                     $('input[name=productSate]').val('审核中');
                 }else if(obj.productSate==3){
                     $('input[name=productSate]').val('审核通过');
                 }else if(obj.productSate==4){
                     $('input[name=productSate]').val('审核已驳回');
                 }
                 if(obj.states==1){
                     $('input[name=state]').val('已上线');
                 }else if(obj.states==2){
                     $('input[name=state]').val('已下线');
                 }
                 $('input[name=productCode]').val(obj.productCode);
                     if(obj.productSales==null){
                         obj.productSales=0;
                     }
                 $('input[name=productSales]').val(obj.productSales+" 件");
                 $('input[name=productLabel]').val(obj.productLabel);
                 //服务保证（2退货无忧，3快速退款，4包邮，5不包邮）
                 if(obj.ensure=='2'){
                     $('input[name=ensure]').val('退货无忧');
                 }else if(obj.ensure=='3'){
                     $('input[name=ensure]').val('快速退款');
                 }else if(obj.ensure=='4'){
                     $('input[name=ensure]').val('包邮');
                 }else if(obj.ensure=='5'){
                     $('input[name=ensure]').val('不包邮');
                 }

                     if(obj.fabuloues==null){
                         obj.fabuloues=0;
                     }
                 $('input[name=fabulous]').val(obj.fabuloues);
                     if(obj.collectionVolumes==null){
                         obj.collectionVolumes=0;
                     }
                 $('input[name=collectionVolume]').val(obj.collectionVolumes);
                     if(obj.hits==null){
                         obj.hits=0;
                     }
                 $('input[name=hits]').val(obj.hits);

                 for(var a=0; a<obj.microcircleImg.length;a++) {
                     $(".td4").append("<img src="+obj.microcircleImg[a].picture_url+" id=\"img\">")
                 }

                 //$(".td4").append("<img src="+obj.mainImage+" id=\"img\">")
                 $(".td5_p").html(obj.productDescription);
             }
         },
         error: function () {
             layer.msg('数据出错！');
         }
     });
 };
 /*日期转换*/
    function settime(da){
        var date=new Date(da);
        var year=date.getFullYear();
        var month=date.getMonth()+1;
        var day=date.getDate();
        var hours=date.getHours();
        var mm=date.getMinutes();
        var s=date.getSeconds();
        return year+'-'+add(month)+'-'+add(day)+' '+add(hours)+':'+add(mm)+':'+add(s);
        //return year+'-'+month+'-'+day+' '+hours+':'+mm+':'+s;
    };
    function add(time){//给非整数添0
        return time<10?'0'+time:time;
    };
    var liminum=0;
    //评论区
    function getcomment() {
        var id=$("#courseId").val();
        var com="";
        var type=4;
        $.post("/SyOperationController/selCommentInfo", {"id":id,"type":type}, function (res) {
            if (res.code>-1) {
                if(res.data.length!=0){
                    liminum=res.data.length;
                    for(var i=0;i<res.data.length;i++){
                        if(res.data[i].userImg!=null){
                            com+="<li class='ulli'><div class='lidiv'>" +
                                "<div class='lidiv1'><div class='liImgdiv'><img class='UserImg' src='"+res.data[i].userImg+"'/></div></div>" +
                                "<div class='licondiv'><p class='userNane'>"+res.data[i].userName+"</p>" +
                                "<p class='comp'>"+res.data[i].content+"</p>" +
                                "<p class='actp'>"+settime(res.data[i].commentDate)+ "" +
                                "<span class='pspupd' onclick='updComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>隐藏</span>" +
                                "<span class='pspdel' onclick='delComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>删除</span></p></div>" +
                                "<input class='comid' value='"+res.data[i].id+"' type='hidden' name='comid'></div></li>";
                        }else {
                            com+="<li class='ulli'><div class='lidiv'>" +
                                "<div class='lidiv1'><div class='liImgdiv'><i class='layui-icon' class='li_i'>&#xe612;</i></div></div>" +
                                "<div class='licondiv'><p class='userNane'>"+res.data[i].userName+"</p>" +
                                "<p class='comp'>"+res.data[i].content+"</p>" +
                                "<p class='actp'>"+settime(res.data[i].commentDate)+
                                "<span class='pspupd' onclick='updComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>隐藏</span>" +
                                "<span class='pspdel' onclick='delComment(\""+res.data[i].id+"\",\""+res.data[i].content+"\")'>删除</span></p></div>" +
                                "<input class='comid' value='"+res.data[i].id+"' type='hidden' name='comid'></div></li>";
                        }
                    }
                    $("#commentUl").html(com);
                    $('#nocomDiv').css("display","block");
                }else{
                    $('#nocomDiv').css("display","block");
                }
            } else {
                $('#nocomDiv').css("display","block");
            }
        });
    }
    //评论状态修改
    function updComment(id,content) {
        var status=2;
            layer.confirm("您确定要拦截`"+content+"`评论吗?",function (rel) {
                $.ajax({
                    url: "/SyOperationController/updComment",
                    type: "post",
                    dataType: "json",
                    data:{"id":id,"status":status},
                    success: function (data) {
                        if(data.code==0){
                            layer.msg("拦截成功",{icon:1});
                            getcomment();
                        }else{
                            layer.msg("拦截失败",{icon:2});
                            getcomment();
                        }
                    }
                });
            },function (res) {
            });
    }
    //评论状态修改为删除
    function delComment(id,content) {
        layer.confirm("您确定要删除`"+content+"`评论吗?",function (rel) {
            $.ajax({
                url: "/SyOperationController/updComment",
                type: "post",
                dataType: "json",
                data:{"id":id,"status":3},
                success: function (data) {
                    if(data.code==0){
                        layer.msg("删除成功",{icon:1});
                        getcomment();
                    }else{
                        layer.msg("删除失败",{icon:2});
                        getcomment();
                    }
                }
            });
        },function (res) {
        });
    }
    //评论文章
    function addCommentInfo(){
        var vals = "";
        var content = $("#textsId").val();
        if(!content){
            layer.msg("内容不能为空",{icon:5});
        }else{
            var create=localStorage.getItem("user");
            create=JSON.parse(create);//将获取json字符串转json对象
            var userId = create.user_id;
            var commodityId=$("#courseId").val();
            vals+="&userId="+userId;
            vals+="&commodityId="+commodityId;
            vals+="&content="+content;
            vals+="&type="+4;
            $.post("/SyOperationController/addCommentInfo", vals, function (res) {
                if(res.code>-1){
                    layer.msg("评论成功",{icon:1});
                    $("#textsId").val('');
                    getcomment();
                }else{
                    layer.msg("评论失败",{icon:2});
                    getcomment();
                }
            });
        }
    }